/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.ReceivableAgeBean;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class ReceivableAgeListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"ReceivableAgeList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints(10);
		font.setColor(10);
		font.setFontName("黑体");
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderBottom(1);
		cellStyle.setWrapText(true);
		cellStyle.setFillForegroundColor(22);
		cellStyle.setFillPattern(1);
		HSSFSheet sheet = workbook.createSheet("list");
		String[] monthArr = (String[]) model.get("monthArr");
		HSSFRow r = sheet.createRow(0);
		r.createCell(0).setCellValue(new HSSFRichTextString("客户名称"));
		r.createCell(1).setCellValue(new HSSFRichTextString("欠款合计"));

		for (int list = 0; list < monthArr.length; ++list) {
			r.createCell((short) (2 + list)).setCellValue(
					new HSSFRichTextString(monthArr[list]));
		}

		r.createCell((short) (2 + monthArr.length)).setCellValue(
				new HSSFRichTextString("1年前"));
		Object[] arg13 = (Object[]) model.get("list");

		for (int totalBean = 0; totalBean < arg13.length; ++totalBean) {
			ReceivableAgeBean os = (ReceivableAgeBean) arg13[totalBean];
			r = sheet.createRow(1 + totalBean);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(os.getEstName()));
			r.createCell(1).setCellValue(os.getRemCost().doubleValue());

			for (int j = 0; j < monthArr.length; ++j) {
				r.createCell((short) (2 + j)).setCellValue(
						os.getMonthCost()[j].doubleValue());
			}

			r.createCell((short) (2 + monthArr.length)).setCellValue(
					os.getYearBefCost().doubleValue());
		}

		ReceivableAgeBean arg14 = (ReceivableAgeBean) model.get("totalBean");
		r = sheet.createRow(1 + arg13.length);
		r.createCell(0).setCellValue(new HSSFRichTextString("合计"));
		r.createCell(1).setCellValue(arg14.getRemCost().doubleValue());

		for (int arg15 = 0; arg15 < monthArr.length; ++arg15) {
			r.createCell((short) (2 + arg15)).setCellValue(
					arg14.getMonthCost()[arg15].doubleValue());
		}

		r.createCell((short) (2 + monthArr.length)).setCellValue(
				arg14.getYearBefCost().doubleValue());
		ServletOutputStream arg16 = response.getOutputStream();
		workbook.write(arg16);
		arg16.flush();
		arg16.close();
	}
}